package bss.queries;

import bss.db.*;

import java.sql.Date;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;


public class Query_Q5   {
	static final Date const_0 = Date.valueOf("1995-12-01");;
	static final Comparator<ProjClass_0> comp_0 = Comparator.comparing((ProjClass_0 row) -> row.l_orderkey());

	private final class ProjClass_0 {
		public final double l_extendedprice;
		public final int l_orderkey;

        private ProjClass_0(double lExtendedprice, int lOrderkey) {
            l_extendedprice = lExtendedprice;
            l_orderkey = lOrderkey;
        }

		public double l_extendedprice() {
			return l_extendedprice;
		}

		public int l_orderkey() {
			return l_orderkey;
		}
	}

	private final class ProjClass_1 {
		public final double l_extendedprice;

        private ProjClass_1(double lExtendedprice) {
            l_extendedprice = lExtendedprice;
        }
    }
//	public record ProjClass_0(double l_extendedprice,int l_orderkey) {}
//
//	public record ProjClass_1(double l_extendedprice) {}

	// methods
	public List<ProjClass_1> exec(DB db) {
		return Arrays.stream(db.lineitem)
				.filter(row -> (row.l_shipdate.compareTo(const_0) >= 0))
				.map(row -> new ProjClass_0(row.l_extendedprice, row.l_orderkey))
				.sorted(comp_0)
				.limit(1000)
				.map(row -> new ProjClass_1(row.l_extendedprice()))
				.collect(Collectors.toList());
	}

}
